package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicTray;
import cn.stylefeng.guns.modular.basic.mapper.BasicTrayMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicTrayParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicTrayResult;
import  cn.stylefeng.guns.modular.basic.service.BasicTrayService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 托盘表 服务实现类
 * </p>
 */
@Service
public class BasicTrayServiceImpl extends ServiceImpl<BasicTrayMapper, BasicTray> implements BasicTrayService {

    @Override
    public void add(BasicTrayParam param){
        BasicTray entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicTrayParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicTrayParam param){
        BasicTray oldEntity = getOldEntity(param);
        BasicTray newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicTrayResult findBySpec(BasicTrayParam param,Long operateId){
        return this.baseMapper.findBySpec(param, operateId);
    }

    @Override
    public List<BasicTrayResult> findListBySpec(BasicTrayParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicTrayParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicTrayParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicTray getOldEntity(BasicTrayParam param) {
        return this.getById(getKey(param));
    }

    private BasicTray getEntity(BasicTrayParam param) {
        BasicTray entity = new BasicTray();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public BasicTray findByThelastone() {
		return this.baseMapper.findByThelastone();
	}

	@Override
	public boolean saveBatchList(List<BasicTray> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public boolean batchupdate(List<BasicTrayParam> tList) {
		return this.baseMapper.batchupdate(tList);
	}

	@Override
	public Integer addReturnId(BasicTrayParam param) {
		return this.baseMapper.addReturnId(param);
	}

	@Override
	public void deleteBySpec(BasicTrayParam param) {
		this.baseMapper.deleteBySpec(param);
	}

}
